package com.tz.dream.architect.mvp.framework.support.viewstate.fragment;

import com.tz.dream.architect.mvp.framework.MvpFragment;
import com.tz.dream.architect.mvp.framework.MvpPresenter;
import com.tz.dream.architect.mvp.framework.MvpView;
import com.tz.dream.architect.mvp.framework.support.fragment.FragmentMvpDelegate;
import com.tz.dream.architect.mvp.framework.support.viewstate.MvpViewStateDelegateCallback;
import com.tz.dream.architect.mvp.framework.support.viewstate.ViewState;

/**
 * 作者: Dream on 2018/4/20 20:53
 * QQ:510278658
 * E-mail:510278658@qq.com
 */

//第一重代理：生命周期->Fragment->代理对象
public abstract class MvpViewStateFragment<V extends MvpView,
        P extends MvpPresenter<V>, VS extends ViewState<V>> extends MvpFragment<V, P> implements MvpViewStateDelegateCallback<V, P, VS>{

    //特点：持有目标对象引用
    @Override
    protected FragmentMvpDelegate<V, P> getMvpDelegate() {
        if (mvpDelegate == null){
            mvpDelegate = new FragmentMvpViewStateDelegateImpl<V, P, VS>(this, this, true, true);
        }
        return mvpDelegate;
    }

    protected VS viewState;

    //是否正在恢复
    private boolean restoringViewState = false;

    @Override
    public VS getViewState() {
        return viewState;
    }

    @Override
    public void setViewState(VS viewState) {
        this.viewState = viewState;
    }

    @Override
    public void setRestoringViewState(boolean restoringViewState) {
        this.restoringViewState = restoringViewState;
    }

    @Override
    public boolean isRestoringViewState() {
        return restoringViewState;
    }

}
